/**
 * 
 */
package com.manage.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;


import com.action.AbstractAction;
import com.manage.cache.PayVersionAbilityManager;
import com.manage.cache.PayVersionManager;
import com.manage.cache.SdkProvidersManager;
import com.manage.cache.ThreePayProvidersManager;
import com.manage.model.PayVersionAbility;
import com.manage.model.PayVersion;
import com.manage.model.SdkProviders;
import com.manage.model.ThreePayProviders;
import com.util.Util;


public class PayVersionAbilityAction extends AbstractAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Logger logger;
	
	public PayVersionAbilityAction()
	{
		logger = Logger.getLogger(this.getClass());
	}
	
	public String execute()
	{
		return SUCCESS;
	}

	private List<PayVersionAbility> list;
	private PayVersionAbility model;
	private String        type;
	private PayVersion payversion;
	
	private List<SdkProviders> sdklist;
	private List<ThreePayProviders> threepaylist;
	private String payid;
	
	public String show()
	{
		logger.debug("show PayVersionAbilityAction");
		payversion = PayVersionManager.getInstance().getPayVersion(model.getPayversionid());
		list =  PayVersionAbilityManager.getInstance().getPayVersionAbilityByPayVersionId(model.getPayversionid());
		sdklist = SdkProvidersManager.getInstance().getSdkProviders();
		threepaylist = ThreePayProvidersManager.getInstance().getThreePayProviders();
		return SUCCESS;
	}
	 
	public String save()
	{
		System.out.println(payid);
		list = new ArrayList<PayVersionAbility>();
		if(payid!=null && !payid.equals(""))
		{
			String str[] = payid.replaceAll(" ", "").split(",");
			PayVersionAbility pva = null;
			for(int i=0;i<str.length;i++)
			{
				String s[] = str[i].split("_");
				if(s.length==2)
				{
					pva = new PayVersionAbility();
					pva.setId(-1);
					pva.setPaysdkid(Integer.parseInt(s[1]));
					pva.setPaytype(s[0]);
					pva.setPayversionid(model.getPayversionid());
					pva.setCreatedate(Util.dateToString(new Date()));
					pva.setCreateuser(operator.getName());
					list.add(pva);
				}
			}
		}
		PayVersionAbilityManager.getInstance().savePayVersionAbility(operator, type, list, model.getPayversionid());
		return SUCCESS;
	}

	public List<PayVersionAbility> getList() {
		return list;
	}

	public void setList(List<PayVersionAbility> list) {
		this.list = list;
	}

	public PayVersionAbility getModel() {
		return model;
	}

	public void setModel(PayVersionAbility model) {
		this.model = model;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public PayVersion getPayversion() {
		return payversion;
	}

	public void setPayversion(PayVersion payversion) {
		this.payversion = payversion;
	}

	public List<SdkProviders> getSdklist() {
		return sdklist;
	}

	public void setSdklist(List<SdkProviders> sdklist) {
		this.sdklist = sdklist;
	}

	public List<ThreePayProviders> getThreepaylist() {
		return threepaylist;
	}

	public void setThreepaylist(List<ThreePayProviders> threepaylist) {
		this.threepaylist = threepaylist;
	}

	public String getPayid() {
		return payid;
	}

	public void setPayid(String payid) {
		this.payid = payid;
	}
	
	
}
